package com.leesche.zcsp.node.web.service.impl;

import com.leesche.zcsp.node.web.dao.PubDiscountCodeDao;
import com.leesche.zcsp.node.web.model.PubDiscountCode;
import com.leesche.zcsp.node.web.model.PubDiscountCodeCriteria;
import com.leesche.zcsp.node.web.service.PubDiscountCodeService;
import com.leesche.zcsp.node.web.service.impl.data.read.InfoDiscountCountDto;
import com.leesche.zcsp.node.web.service.impl.data.read.PubDiscountCodeDto;
import com.leesche.zcsp.node.web.service.impl.data.read.QueryPubDiscountCodeCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2016-11-16.
 */
@Service
@Transactional
public class PubDiscountCodeServiceImpl extends BaseServiceImpl<PubDiscountCode, PubDiscountCodeCriteria, PubDiscountCodeDto, QueryPubDiscountCodeCondition, Long>
        implements PubDiscountCodeService {
    @Autowired
    private PubDiscountCodeDao pubDiscountCodeDao;

    @Autowired
    public void setBaseDao(PubDiscountCodeDao pubDiscountCodeDao) {
        super.setBaseDao(pubDiscountCodeDao);
    }

    @Override
    public boolean selectCheck(QueryPubDiscountCodeCondition codeCondition) {
        Integer count = pubDiscountCodeDao.selectCheck(codeCondition);
        boolean flag;
        if(count>1){
            flag = true;
        }else{
            flag = false;
        }
        return flag;
    }

    @Override
    public PubDiscountCode selectByModel(QueryPubDiscountCodeCondition codeCondition) {
        return pubDiscountCodeDao.selectByModel(codeCondition);
    }

    @Override
    public int selectCodeNum(QueryPubDiscountCodeCondition codeCondition) {
        return pubDiscountCodeDao.selectCodeNum(codeCondition);
    }

    @Override
    public List<InfoDiscountCountDto> selectCodeTypeNum(QueryPubDiscountCodeCondition codeCondition) {
        return pubDiscountCodeDao.selectCodeTypeNum(codeCondition);
    }

    /**
     * 条件查询优惠码列表
     * @param condition
     * @return
     */
    @Override
    public List<PubDiscountCode> findListByCondition(QueryPubDiscountCodeCondition condition) {
        return pubDiscountCodeDao.findListByCondition(condition);
    }

    @Override
    public int insertBatch(List<PubDiscountCode> list) {
        return pubDiscountCodeDao.insertBatch(list);
    }
}
